﻿using System;
using System.Collections.Generic;
using System.Text;
using mvLibrary.Helpers.Querys;
using IBMU2.UODOTNET;

namespace mvLibrary.Helpers
{
    public class ControlsInitializer
    {
        private static ControlsInitializer instance;
        private readonly ProgramCaller programCaller;
        private ControlsInitializer()
        {
            this.programCaller = ProgramCaller.Instance;
        }

        public static ControlsInitializer Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ControlsInitializer();
                }
                return instance;
            }
        }

        public void InitializePrintersLabel(UniSession uniSession, controls.MvPrintersLabel mvPrintersLabel)
        {
            string printerNameFormat = "{0} - {1} \n";
         
            UniDynArray itemList = this.programCaller.ExecuteSelectNetProgram(uniSession, "PRINTERS", "1", "BY 0",
                                                                         string.Empty);

            var items = PickResultsFormatter.ItemListToDictionary(itemList);


            StringBuilder printers = new StringBuilder();
            foreach (var itemKey in items.Keys)
            {
                printers.Append(string.Format(printerNameFormat, itemKey, items[itemKey]));
            }

            mvPrintersLabel.Text = printers.ToString();
        }
    }
}
